/*
 * 太原科技大学。
 * Copyright 2021, YCHS Information&Science Technology Co.,Ltd,
 * All rights reserved.
 */
package com.example.demo.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * @author liuchao
 * @version 1.0
 * @date 2024/9/12
 */

@Configuration
@Slf4j
public class RedisConfig {


    //这里使用StringRedisTemplate可以不用序列化就让string类型数据不会乱码
    @Bean
    public StringRedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory){
        log.info("开始创建redis模板对象");
        StringRedisTemplate redisTemplate=new StringRedisTemplate();
        //设置redis连接对象
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        //如果需要其他格式数据记得设置序列化器
        //redisTemplate.setKeySerializer(new StringRedisSerializer());
        return redisTemplate;
    }
}
